package org.xdq.demo.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.xdq.demo.dto.EmployeeDto;
import org.xdq.demo.model.Employee;
import org.xdq.demo.service.EmployeeService;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.*;

@Controller  //说明这是一个受spring容器管理的组件，而且是一个控制器组件
public class TestController {

    @RequestMapping("/hello")
    public String sayHello(Model model){
        model.addAttribute("info", "这是一个短信息！");
        return "/1.jsp";//返回值是网页路径,表示请求转发到某个网页
    }

    @RequestMapping(value="/hello2",produces = "text/plain;charset=UTF-8")
    @ResponseBody //说明返回值就是响应体，即将返回值直接发送至前端
    public String sayHello2(){

        return "大家好！";
    }

    @RequestMapping("/arr")
    @ResponseBody
    public List<Integer> arr(){
        int n = 10;
        List<Integer> list = new ArrayList<>();
        for(int i=0;i<n;i++){
            list.add((int)(Math.random()*99999));
        }
        return list;
    }

    @RequestMapping("/map")
    @ResponseBody
    public Map<String,Object> map(){
        Map<String ,Object> map = new HashMap<>();
        map.put("e_id", 123456);
        map.put("e_name", "员工某某");
        map.put("e_date", new Date());
        return map;

    }

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("/emps")
    @ResponseBody
    public List<Employee> empList(EmployeeDto dto){

        List<Employee> list = employeeService.getEmployeeList(dto);

        return list;
    }





}
